import com.codezen.helper.Worker;

import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.utils.ObjectUtil;

private function loadNewMovies():void{
	kb.addEventListener(Event.COMPLETE, onNewMovies);
	kb.loadNewMovies();
}

private function onNewMovies(e:Event):void{
	kb.removeEventListener(Event.COMPLETE, onNewMovies);
	
	// get list
	moviesList = kb.newSeries;
	
	// break generes
	var item:Object;
	var generes:Array = new Array();
	for each(item in moviesList){
		if(generes.indexOf(item.genere) < 0){
			generes.push(item.genere);
		}
	}
	
	// assign list
	generesList = new ArrayCollection(generes);
	movies_genere_list.selectedIndex = 0;
	filterMovies();
	
	// load new Series
	loadNewSeries();
}

private function loadNewSeries():void{
	kb.addEventListener(Event.COMPLETE, onNewSeries);
	kb.loadTopSeries();
}

private function onNewSeries(e:Event):void{
	kb.removeEventListener(Event.COMPLETE, onNewSeries);
	
	// get list
	newSeriesList = kb.newSeries;
}

private function filterMovies():void{
	moviesList.filterFunction = function(obj:Object):Boolean{
		return obj.genere == movies_genere_list.selectedItem;
	};
	moviesList.refresh();
}